//
//  YKFarmDetailController.m
//  YK_BaseMediator
//
//  Created by edward on 2021/3/11.
//  Copyright © 2021 Edward. All rights reserved.
//

#import "YKFarmDetailController.h"
#import "YKFarmViewModel.h"
#import <YK_TableRefresh/YK_TableRefresh.h>
#import <Masonry/Masonry.h>
#import "YKFarmEverDayController.h"
#import "YKFarmWaterViewController.h"
#import "YKFarmFoodListViewController.h"
#import "YKFarmDrugListController.h"
#import <YK_ExectionModel/YKNSObjectCore.h>
#import <YK_ExectionModel/YKUIKitCore.h>

@interface YKFarmDetailController ()<UITableViewDelegate,UITableViewDataSource>
///
@property(nonatomic,strong) YKFarmViewModel *viewModel;
///
@property(nonatomic,strong) UITableView *tableView;
///
@property(nonatomic,copy) NSString *farmId;
@end

@implementation YKFarmDetailController

- (instancetype)initWithViewModel:(YKFarmViewModel *)viewModel farmId:(NSString *)farmId
{
    self = [super init];
    if (self) {
        self.farmId = farmId;
        self.viewModel = viewModel;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.tableView];
}

#pragma mark -tableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(UITableViewCell.class)];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:NSStringFromClass(UITableViewCell.class)];
        cell.backgroundColor = UIColor.clearColor;
        cell.contentView.backgroundColor = UIColor.clearColor;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    NSString *title = @"";
    switch (indexPath.row) {
        case 0:
        {
            title = @"每日必做";
        }break;
        case 1:
        {
            title = @"检测水质";
        }break;
        case 2:
        {
            title = @"喂料记录";
        }break;
        case 3:
        {
            title = @"喂药记录";
        }break;
            
        default:
            break;
    }
    cell.textLabel.text = title;
    cell.textLabel.font = [UIFont systemFontOfSize:20];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
        {
            YKFarmEverDayController *vc = [[YKFarmEverDayController alloc] initWithViewModel:self.viewModel farmId:self.farmId];
            vc.title = @"每日必做";
            [self.navigationController pushViewController:vc animated:YES];
        }break;
        case 1:
        {
            YKFarmWaterViewController *vc = [[YKFarmWaterViewController alloc] initWithViewModel:self.viewModel farmId:self.farmId];
            vc.title = @"检测水质";
            [self.navigationController pushViewController:vc animated:YES];
        }break;
        case 2:
        {
            YKFarmFoodListViewController *vc = [[YKFarmFoodListViewController alloc] initWithViewModel:self.viewModel farmId:self.farmId];
            vc.title = @"喂料记录";
            [self.navigationController pushViewController:vc animated:YES];
        }break;
        case 3:
        {
            YKFarmDrugListController *vc = [[YKFarmDrugListController alloc] initWithViewModel:self.viewModel farmId:self.farmId];
            vc.title = @"喂药记录";
            [self.navigationController pushViewController:vc animated:YES];
        }break;
            
        default:
            break;
    }
}

- (UITableView *)tableView
{
    if(!_tableView)
    {
        UITableView *tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
        tableView.dataSource = self;
        tableView.delegate = self;
        tableView.estimatedRowHeight = 60;
        tableView.rowHeight = 80;
        tableView.backgroundColor = UIColor.clearColor;
        @weakify(self);
        [tableView registerClass:UITableViewCell.class forCellReuseIdentifier:UITableViewCell.defaultIdentifier];
        _tableView = tableView;
    }
    return _tableView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
